<template>
  <div class="container">
    <div id="playWnd" style="width: 900px; height: 500px"></div>
  </div>
</template>

<script>
// import WebControl from '../../../utils/web-control.min.js'
export default {
  data() {
    return {
      oWebControl: null,
      callbackMessage: '', //显示回调信息
      volumeInfo: {
        index: -1,
        volumeSwitch: 0,
        volume: 0,
      },
    }
  },
  computed: {},
  mounted() {
    console.log('test————————挂载')
    console.log(WebControl, 'WebControl')
    const cbConnectSuccess = this.cbConnectSuccess()
    const cbConnectError = this.cbConnectError()
    const cbConnectClose = this.cbConnectClose()
    const wxx = this.WebControlInit(
      'playWnd',
      this.cbConnectSuccess(),
      this.cbConnectError(),
      this.cbConnectClose()
    )
    console.log('[ wxx ] >', wxx)
    this.oWebControl = wxx
  },

  methods: {
    initVideo() {
      let argumentsPram = {
        layout: +self.layout,
        userName: 'test@qq.com',
        waterMark: '1',
        iWndType: 0,
        intelligenceEnable: 1,
        isRecord: 1,
        iPreviewHideItem: 4194304,
        iPlayBackHideItem: 0,
        iConfigItem: 3,
        isPtzRight: 1,
        isSetPos: 1,
        motionDetectEnable: 0,
        playBackAlarmOverlyingEnable: 0,
        token: self.accessToken,
        response: {
          code: 0,
          message: null,
          data: {
            appKey: '123456',
            ezvizToken: '666666',
            videoLevel: 0,
            showMainTool: 1,
            showSubTool: 1,
            waterMark: '1',
            userName: 'test@qq.com',
            EZVIZ_AuthAddr: '',
            EZVIZ_PlatAddr: '',
          },
        },
      }
      argumentsPram.eagleEyeAPIPrefix = 'https://nissan.hik-cloud.com'
      console.log('初始化入参', argumentsPram)
      // 调用视频控件初始化方法
      oWebControl
        .JS_RequestInterface({
          funcName: 'Init',
          arguments: encodeURI(JSON.stringify(argumentsPram)),
        })
        .then(function (oData) {
          console.log('初始化成功')
        })
    },

    WebControlInit(id, cbConnectSuccess, cbConnectError, cbConnectClose) {
      this.$nextTick(() => {
        return new WebControl({
          szPluginContainer: id,
          iServicePortStart: 14510, // 对应 LocalServiceConfig.xml 中的ServicePortStart值
          iServicePortEnd: 14519, // 对应 LocalServiceConfig.xml 中的ServicePortEnd值
          cbConnectSuccess: cbConnectSuccess, // 成功回调
          cbConnectError: cbConnectError, // 失败回调
          cbConnectClose: cbConnectClose, // 意外断开回调
        })
      })
    },
    showCBInfo(message) {
      this.callbackMessage =
        this.callbackMessage + JSON.stringify(message) + '\n\n'
    },
    // 监听视频控件的事件
    cbIntegrationCallBack(oData) {
      this.showCBInfo(oData)
      if (oData.responseMsg.eventName === 'FireTransFunction') {
        // 如果视频控件需要请求服务端数据，这里可以处理透传逻辑
      } else if (oData.responseMsg.eventName === 'FireOcxVolumeInfo') {
        this.volumeInfo = oData.responseMsg.arguments
      }
    },
    // 成功回调
    cbConnectSuccess() {
      this.$nextTick(() => {
        // 设置窗口控制回调
        console.log(' this.oWebControl222222', this.oWebControl)

        this.oWebControl.JS_SetWindowControlCallback({
          cbIntegrationCallBack: this.cbIntegrationCallBack(),
        })
        // 创建视频窗口
        this.oWebControl
          .JS_StartService('window', {
            dllPath: './chain/cloudTransform.dll',
          })
          .then(function () {
            oWebControl.JS_CreateWnd('playWnd', 900, 500).then(function () {
              console.log('JS_CreateWnd success')
              oWebControl.JS_RequestInterface({
                funcName: 'GetOCXVersion',
              })
            })
          })
      })
    },
    // 失败回调
    cbConnectError() {
      console.log('cbConnectError----------cbConnectError')
      this.oWebControl = null
      console.error('确认本地进程是否已安装并开启成功！')
    },
    cbConnectClose(bNormalClose) {
      // 连接异常断开：bNormalClose = false
      // JS_Disconnect正常断开：bNormalClose = true
      console.log('cbConnectClose-----------')
      this.oWebControl = null
    },
  },
  beforeDestroy() {},
}
</script>

<style scoped></style>
